package com.xiaotou.domain;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Properties;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class RuleParam {

	private String propertiesPath;

	private Properties properties = new Properties();

	@Value("${xiaotou.ruleparam.properties.path}")
	public void setPropertiesPath(String propertiesPath) {
		this.propertiesPath = propertiesPath;
	}

	public String getPropertiesPath() {
		return this.propertiesPath;
	}

	@PostConstruct
	public void reload() throws FileNotFoundException, IOException {
		this.properties.load(new FileReader(this.propertiesPath));
	}

	public void store() throws IOException {
		this.properties.store(new FileWriter(this.propertiesPath),
				"Rule parameter");
	}

	public int getRichThreshold() {
		return Integer.valueOf(this.properties.get("wealth.rich.threshold")
				.toString());
	}

	public int getMiddleThreshold() {
		return Integer.valueOf(this.properties.get("wealth.middle.threshold")
				.toString());
	}

	public int getMoneyWeights() {
		return Integer.valueOf(this.properties.get("weights.prey.money")
				.toString());
	}

	public int getBeginnerThreshold() {
		return Integer.valueOf(this.properties.get("skill.beginner.threshold")
				.toString());
	}

	public int getExpertThreshold() {
		return Integer.valueOf(this.properties.get("skill.expert.threshold")
				.toString());
	}
}
